package com.kajespero.domain.user.impl;

import java.util.List;

import com.kajespero.dao.user.impl.UserDAOImpl;
import com.kajespero.domain.commons.impl.AbstractReadWriteDomain;
import com.kajespero.domain.user.UserDomain;
import com.kajespero.jdo.Criteria;
import com.kajespero.model.UserBean;
import com.kajespero.model.annotation.process.MappedValueProcess;

public class UserDomainImpl extends AbstractReadWriteDomain<UserDAOImpl, UserBean, Long> implements UserDomain{

	@Override
	public UserBean findByAuthentificate(String login, String password) {
		Criteria<UserBean> criteria = new Criteria<UserBean>(UserBean.class);
		criteria.addProperty("surName", login);
		criteria.addProperty("password", password);
		List<UserBean> users = (List<UserBean>) criteria.executeCriteria();
		if(users != null && !users.isEmpty()){
			return MappedValueProcess.processPostLoad(users.get(0));
		}
		return null;
	}
}
